﻿using System.ComponentModel;
using VNet.VisiSuite.Common.Resource;

namespace VNet.VisiSuite.VisiAdmin.Models
{
    public class LoginModel : ComparableBaseModel<LoginModel>, IDataErrorInfo
    {
        private string _userName;
        private string _password;
        private string _installKey;
        private string _serviceUrl;

        public string ServiceUrl
        {
            get { return _serviceUrl; }
            set
            {
                _serviceUrl = value;
                OnPropertyChanged("ServiceUrl");
            }
        }

        public string InstallKey
        {
            get { return _installKey; }
            set
            {
                _installKey = value;
                OnPropertyChanged("InstallKey");
            }
        }

        public string Password
        {
            get { return _password; }
            set
            {
                _password = value; OnPropertyChanged("Password");
            }
        }

        public string UserName
        {
            get { return _userName; }
            set
            {
                _userName = value; OnPropertyChanged("UserName");
            }
        }

        #region Implementation of IDataErrorInfo

        public string Error
        {
            get { return string.Empty; }
        }

        public string this[string columnName]
        {
            get
            {
                if (!ShouldValidate)
                    return string.Empty;

                if (columnName == "UserName" && string.IsNullOrWhiteSpace(_userName))
                    return ValidationMessages.UsernameRequired;
                if (columnName == "Password" && string.IsNullOrWhiteSpace(_password))
                    return ValidationMessages.PasswordRequired;
                if (columnName == "ServiceUrl" && string.IsNullOrWhiteSpace(_serviceUrl))
                    return ValidationMessages.ServiceUrlRequired;
                if (columnName == "InstallKey" && string.IsNullOrWhiteSpace(_installKey))
                    return ValidationMessages.InstallKeyRequired;
                return string.Empty;
            }
        }

        #endregion
    }
}
